package com.pehulja.mmdo.coursework.math.matrix;

import java.util.*;

/**
 * This class implements some useful static methods, that uses while working mathematical algorithm
 */
public class Operations {

    /**
     * Generate sequence of unique in sequence integers
     * @param start The lower border of the range of generated sequence
     * @param end   The higher border of the range of generated sequence
     * @param n Number of elements in generated sequance
     * @return  Integer sequence
     */
    public static Integer[] generateRandomUniqSequence(int start, int end, int n){
        //Checking if it is possible to generate UNIQUE sequence according to input params
        if((end - start)>=(n-1)){
            Set<Integer> set = new HashSet<Integer>();
            Random random = new Random();
            while(set.size()<n)
                set.add(random.nextInt(start+end+1)-start);
            return set.toArray(new Integer[0]);
        }else
            return null;
    }

    /**
     * Generate factorial of @param n
     * @param n
     * @return factorial
     */
    public static int factorial(int n)
    {
        if (n == 0) return 1;
        return n * factorial(n-1);
    }


}
